﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Speedy
{
    public partial class frmVergi : XtraForm
    {
        DataTable dt;
        public frmVergi()
        {
            InitializeComponent();
            dt = new DataTable();
            dt.Columns.Add("Sıra", typeof(int));
            dt.Columns.Add("Açıklama", typeof(string));
            dt.Columns.Add("Oran", typeof(int));

            dt.Rows.Add(0, "Vergisi Tanımsız", 0);
            dt.Rows.Add(1, "YOK", 0);
            dt.Rows.Add(2, "K.D.V (%) 1", 1);
            dt.Rows.Add(3, "K.D.V (%) 8", 8);
            dt.Rows.Add(4, "K.D.V (%) 18", 18);
            dt.Rows.Add(5, "K.D.V (%) 26", 26);

            for (int i = 6; i < 10; i++)
                dt.Rows.Add(i, "", 0);

            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();
            gridView1.Columns["Sıra"].OptionsColumn.AllowEdit = false;
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            dbVergi ver = new dbVergi();
            if (dt != null)
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ver.id.SetValue(dt.Rows[i]["Sıra"]);
                    ver.name.SetValue(dt.Rows[i]["Açıklama"]);
                    ver.rate.SetValue(dt.Rows[i]["Oran"]);
                    ver.Save();
                }
            this.Close();
        }

        private void frmVergi_Load(object sender, EventArgs e)
        {
            dbVergi ver = new dbVergi();
            ver.id.Alias = "ID";
            ver.name.Alias = "NAME";
            ver.rate.Alias = "RATE";

            DataTable dts = ver.AllData();
            for (int i = 0; i < dts.Rows.Count; i++)
            {
                dt.Rows[i]["Sıra"] = dts.Rows[i]["ID"];
                dt.Rows[i]["Açıklama"] = dts.Rows[i]["NAME"];
                dt.Rows[i]["Oran"] = dts.Rows[i]["RATE"];
            }
        }
    }
}
